{extend name="/base/index"}
{block name="title"}
<title>绑定银行卡</title>
{/block}
{block name="header_person"}			
				<a class="ground-item" href="/index.php/home/index_index" style="text-decoration:none;">个人中心</a>
{/block}
{block name="self_css"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/layer.css"/>
{/block}
{block name="left_bar_security"}
							<li class="submeun-2"><i class="ioc active"></i>
								<a class="l-m-icon active" href="/index.php/security/index.html">安全中心</a><span class="active"></span>
							</li>
						</ul>
						<h3 class="myaccount">我的资金</h3>
						<ul class="menu-son">
{/block}
{block name="right_bar_box_top"}
					<div class="crumbs">
						<div class="container">管理系统&nbsp;&gt;&nbsp;银行卡绑定	</div>
					</div>
{/block}
{block name="right_bar_box"}
					<h1 class="page_title">绑定银行卡</h1>
					<div style="margin: 0;padding: 10px;">
						<ul class="bank-info">
							<li>
								<span>持卡人：</span>
								<span>{$user_bank_info.name}</span>
							</li>

							<li>
								<span>银行名称：</span>
								<span>{$user_bank_info.bank_name}</span>
							</li>

							<li>
								<span>银行卡号：</span>
								<span>{if condition = "($user_bank_info.bank_card neq Null)"}
										{$user_bank_info.bank_card}
										{else /}
										<input style="border: 1px solid grey;line-height: 10px;" type="text" name="bank_card" id="bank_card" placeholder="输入银行卡号进行绑定" />
										<select name="bank_name"  id = "input_bankItems"><option>加载中...</option></select>
										{/if}
								</span>
								<span>
			                    	<a href="javascript:void(0);" class="btn btn-primary" {if condition = "($user_bank_info.bank_card neq Null)"} onclick="return unbindBank(this,'unbind');" data-cleartext="6217856300005629491">解绑{else /} onclick="return unbindBank(this,'bind');" >绑定{/if}</a>
								</span>
							</li>
						</ul>
					</div>
{/block}
{block name="self_js"}
		<!--<div class="layui-layer-move"></div>-->
		<script type="text/javascript" src="__PUBLIC__/js/layer.js"></script>
		<script type="text/javascript" src="__PUBLIC__/js/app.min.js"></script>
		<script type="text/javascript" src="__PUBLIC__/layui/layui.all.js" ></script>
		<script type="text/javascript">
			$(function() {
				$('.actfrm').on('submit', function() {
					var _this = $(this);
					App.getJSON(_this.attr('action'), _this, function(res) {
						if(res.code) {
							layer.alert(res.msg, {
								icon: 6,
								closeBtn: 0
							}, function() {
								location.href = res.url;
							});
						} else {
							layer.alert(res.msg, {
								icon: 5
							});
						}
					}, {
						maskSelector: '.actfrm'
					});
					return false;
				});
			});

			function unbindBank(ele,card_operate_type) {
//				console.log(card_operate_type);return false;
				if(card_operate_type == "bind"){
					//绑定操作
//					console.log(card_operate_type);
					var true_length = new Array(16,18,19);
					var data = {"user_id":$("#user_id").val(),"bank_card":$("#bank_card").val(),"bank_name":$("#input_bankItems").val()};
//					console.log(data['bank_card'].length);
					if((jQuery.inArray(data['bank_card'].length,true_length))){
						layer.alert("银行卡位数不正确",{
							title:'温馨提示',
						});
						$("#bank_card").focus();
						return false;
					}
					$.ajax({
						type:"post",
						data:data,
						url:"/index.php/bank/bind_card",
						success:function(result){
							layer.alert(result['msg']+'_ _ _ 自动加载中...',{title:'温馨提示'});									
							setTimeout(
								function()
								{
									window.location.reload();
								},1500
							)
						},
						async:true
					});
					return false;
				}
				//解除绑定
				layer.confirm('是否确认解绑该银行卡？', {
					closeBtn: 0,
					title: '温馨提示',
					btn: ['确定', '取消']
				}, function() {
					var bank_card = $(ele).data('cleartext');
//					return false;
					data = {"user_id":$("#user_id").val(),"bind_bank":bank_card};
					$.ajax({
						type:"post",
						data:data,
						url:"/index.php/bank/unbind/",
						success:function(result){	
//							console.log(result);return false;
							layer.alert(result['msg']+'_ _ _ 自动加载中...',{title:'来自后台消息'});
							setTimeout(
								function(){									
									if(result['code'] == 1){
										window.location.reload();
									}
								},1500
							)
						},
						error:function(result){
//							console.log(result);
							layer.alert('执行错误!请稍后重试！');
						},
						async:true
					});
				});
				return false;
			}

			function loadEfSupportBanks() {
				App.getJSON("/index.php/bank/efsupportbanks.html", '', function(res) {
//					console.log(res);
					if(res.code) {
						var banks = res.data;
						var options = '';
						for(var i = 0; i < banks.length; i++) {
							options += '<option value="' + banks[i].name + '">' + banks[i].name + '</option>';
						}
						$('#input_bankItems').html(options);
					} else {}
				});
			}
		</script>
		{if condition="($user_bank_info.bank_card eq Null)"}
			<script>loadEfSupportBanks()</script>
		{/if}
{/block}
	</body>
</html>